<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{log_name} : {log_account_no}</title>
<link rel="shortcut icon" href="{dir_image}favicon.ico">
<link rel="stylesheet" type="text/css" href="{dir_css}Global.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Popup.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Registrar.css" />

<script type="text/javascript" src="{dir_js}jquery.min.js"></script>
<script type="text/javascript" src="{dir_js}Global.js"></script>
</head>

<body>
<!-- POPUP -->{page_popup}<!-- POPUP END -->
<!-- TOP HEADER -->{page_header}<!-- TOP HEADER END -->
	<div class="main-content">
		<input type="hidden" id="record_saved" value="{record_saved}"/>
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr valign="top" align="left">
				<td width="220">
					{dean_sub_menu}
				</td>
				<td width="755">
					<div class="page-sub-content">
						<div class="float-right-back"><a href="?page=Students"><img src="{dir_image}icon/back.png" border="0"/></a></div>	
						<div class="ann-top-label">Students Record</div>
						<table width="0" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td class="reg-student-enroll-td" width="110"><strong>Student #</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{stud_no}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Name</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{last_name} {first_name} {middle_name}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Department</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{dept_desc}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Course</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{course_desc}</td>
							</tr>
							<tr>
								<td colspan="2"></td>
								<td><div class="enrollment-more-details"  onclick="popupRequest('show', 'StudentProfile', 'Student Profile', '390', '500', '{stud_id}');">More Details</div></td>
							</tr>
						</table>
						
						
						<div class="div-reg-transfery">
							<ul class="ul-reg-transfery">
								<li class="li-reg-transfery">Student Enrollment</li>
							</ul>
						</div>
						<div class="div-reg-pointer" id="click_type_reg_transfer">
							{sem_desc} ({sem_code}) |
							<span id="units_label" style="color:#00F; font-size:14px;">Units : <span id="add_units">0</span>/<span id="total_units">-</span></span>
						</div>
						<form method="post" enctype="multipart/form-data" action="" onsubmit="return validateForm()" >
							<div class="enrollment-popup" id="view_enrollment_popup"><!--  display-none -->
								<table width="0" border="0" cellspacing="0" cellpadding="0">
									<tr valign="top">
										<td width="160">
											<div class="previous-grades">
												<!-- BEGIN subjects -->
													{subj_list}
												<!-- END subjects -->
											</div>
										</td>
										<td>
											<input type="hidden" value="{active_subj}" id="active_subj"  />
											<input type="hidden" name="list_subj_taken" id="list_subj_taken" value=""/>
											<input type="hidden" name="active_subj_taken" id="active_subj_taken" value="{active_subj_taken}"/>
											<input type="hidden" id="sem_linker_id" value="{sem_linker_id}"/>
											<input type="hidden" id="sem_taken_active" value="{sem_taken_active}"/>
											<input type="hidden" id="fourth_next_sem" value="{fourth_next_sem}"/>
											<input type="hidden" id="sem_taken_id" value="{sem_taken_id}"/>
											<input type="hidden" id="sem_next_taken" value="{sem_next_taken}"/>
											<input type="hidden" id="stud_id" value="{stud_id}"/>
											<input type="hidden" id="course_id" value="{course_id}"/>
											<input type="hidden" id="course_desc" value="{course_desc}"/>
											<input type="hidden" id="sem_desc" value="{sem_desc}"/>
											<input type="hidden" id="redirect" value="{redirect}"/>
											
											<input type="hidden" id="subj_failed" value="{subj_failed}"/>
											
											<div id="enrollment_popup"></div>
											<div class="ajax-enrollment-value" id="enrollment_value_stud_subj"></div>
										</td>
									</tr>
								</table>

							</div>
							<input type="submit" name="subButton" class="enroll-save-button" value="Save" id="save_submit_button"/>
						</form>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
<!-- FOOTER -->{page_footer}<!-- FOOTER -->
<script type="text/javascript">

	$(document).ready(function() {
		selectGradeTransfery();
	});
	
	function selectGradeTransfery() {
		var strSemLinker = $('#sem_next_taken').val();
		$.post('request.php', {AJAXPost:'gradeTotalUnitsPerSemester', sem_linker_id:strSemLinker}, function(res) {
			$('#total_units').text(res.total_units);
			regular();
		}, 'json');
	}
	
	function regular() {
		
		var sem_next_taken 	   = $('#sem_next_taken').val();
		var sem_desc 		   = $('#sem_desc').val();
		var enrollment_popup   = $('#enrollment_popup');
		var list_subj_taken	   = $('#list_subj_taken');
		var active_subj_taken  = $('#active_subj_taken');
		var sem_taken_active   = $('#sem_taken_active').val();
		var fourth_next_sem    = $('#fourth_next_sem').val();
		var stud_id    	   	   = $('#stud_id').val();
		var course_id    	   = $('#course_id').val();
		
		
		enrollment_popup.html('');
		list_subj_taken.val('');
		
		var sem_enrol_value = '';
		$.post('request.php', {AJAXPost:'InputGradeRequisite', strSubjLinkerID:sem_next_taken, strSemLinkerActiveID:sem_taken_active, stud_id:stud_id, take_course:course_id}, function(res) {
			if (res == 0) {
				enrollment_popup.append('<div class="enrollment-label">' + sem_desc + '</div><div class="ajax-enrollment-value">No Record Found.</div>');
			}
			else {
				
				strArrayActiveSubj = $('#active_subj').val().split('-');
				strArraySubjFailed = $('#subj_failed').val().split('-');
				
				active_subj_taken.val(sem_next_taken);
				
				var value_unit = 0;
						
				$.each(res, function(first_key, first_value) {
					
						getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list');
						
						enrollment_popup.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list' + first_key + '"></div>');
						$.each( first_value, function( key, value ) {
							
							sem_enrol_value = sem_enrol_value + value['subj_idPK'] + ',';
							strResultInArray = $.inArray(value['pre_req'], strArrayActiveSubj);
							
							//alert(value['pre_req']);
							
							if(strResultInArray < 0 || value['pre_req'] == '') {
							
								value_unit += parseInt(Math.abs(value.total_units));
								$('#add_units').text(value_unit);
								
								if (list_subj_taken.val() == '') {
									list_subj_taken.val(value['subj_idPK']);
								}
								else {
									list_subj_taken.val(list_subj_taken.val() + ', ' + value['subj_idPK']);
								}
								
								strResultFailedArray = $.inArray(value['subj_idPK'], strArraySubjFailed);
								/*if(strResultFailedArray < 0) {*/
									enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_check.png" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] + '\');" border="0"  class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
								/*}
								else {
									enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_lock.png" border="0"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
								}*/
							
							}
							else {
								$.post('request.php', {AJAXPost:'InputGradeRequisiteGradeIfDrop', stud_subj_linker_id:value['pre_req'], stud_sem_linker_id:sem_taken_active, stud_id:$('#stud_id').val()}, function(g) {
									if ( g.grade == 'DRP' 	||
										 g.grade == '4' 	||
										 g.grade == '4.0' 	||
										 g.grade == '5'		||
										 g.grade == '5.0' 	||
										 ( g.grade <  '75' && g.grade >  '5' )	) {
										enrollment_popup.append('<div class="enrollment-lock font-grey"><img src="./application/images/icon/checkbox_remove.png" border="0"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
									}
									else {
										enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="0"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_uncheck.png" border="0" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] + '\');" class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
									}
								}, 'json');
							}
						});
						
					});
					
					if ( parseInt($('#total_units').text()) < value_unit ) {
						$('#units_label').css('color', '#F00')	
						$('#save_submit_button').hide();
					}
					else {
						$('#units_label').css('color', '#00F')
						$('#save_submit_button').show();
					}
			}
			$('#sem_enrollees_value').val(sem_enrol_value);
			$('#view_enrollment_popup').slideDown();
		}, 'json');
	}
	
	function getAddSemester(strNextSemID) {
		
		if ($('#next_sem_img').val() == 0) {
			var sem_stud_grade_enroll_list_next = $('#sem_stud_grade_enroll_list_next');
			sem_stud_grade_enroll_list_next.html('');
			$.post('request.php', {AJAXPost:'StudentNextSubjectDetails', strSubjLinkerID:strNextSemID}, function(res) {
				
				$.each(res, function(first_key, first_value) {
						
						getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list_next');
						
						sem_stud_grade_enroll_list_next.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list_next' + first_key + '"></div>');
				
						$.each( first_value, function( key, value ) {
							
							sem_stud_grade_enroll_list_next.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="0"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_uncheck.png" border="0" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] + '\');" class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
							
						});
						
					});
				$('#subj_add_label').text('HIDE');	
				$('#next_sem_img').val(1);	
			}, 'json');
		}
		else {
			window.location.href = window.location.href;
		}
		
	}
	
	function getStudentSemesterDesc(strSem, strDdivID) {
		$.post('request.php', {AJAXPost:'Semester', sem_id:strSem}, function(res) {
			$('#'+strDdivID+strSem).text(res.sem_desc)
		}, 'json');
	}
		
	function studNewEnrollyValue(strID, strValue, strSubjUnits) {
		var list_subj_taken = $('#list_subj_taken');
		
		var add_units  	 = $('#add_units').text();
		var total_units  = parseInt($('#total_units').text());
		 	
		sum_total_comput_units  = parseInt(add_units) + parseInt(Math.abs(strSubjUnits));
		diff_total_comput_units = parseInt(add_units) - parseInt(Math.abs(strSubjUnits));
					
		if (list_subj_taken.val() == '') 
			list_subj_taken.val(strValue);	// Auto Add Value
		else
			list_subj_taken.val(list_subj_taken.val() + ', ' + strValue);
			
		strArray = list_subj_taken.val().split(', ');
		if ( $('#hidden_subj_id'+strID).val() == 0 ) {
			
			if ( total_units < sum_total_comput_units || sum_total_comput_units == 0 ) {
				$('#units_label').css('color', '#F00')	
				$('#save_submit_button').hide();
			}
			else {
				$('#units_label').css('color', '#00F')
				$('#save_submit_button').show();
			}
			
			$('#add_units').text(sum_total_comput_units);
			$('#list_subj_taken').val(strArray.join(", "));
			$('#hidden_subj_id'+strID).val(1);
			$('#but_subj_id'+strID).attr('src','./application/images/icon/checkbox_check.png');
		}
		else {
			
			if ( total_units < diff_total_comput_units || diff_total_comput_units == 0) {
				$('#units_label').css('color', '#F00')	
				$('#save_submit_button').hide();
			}
			else {
				$('#units_label').css('color', '#00F')
				$('#save_submit_button').show();
			}
			
			$('#add_units').text(diff_total_comput_units);
			
			arr = $.grep(strArray, function(n, i){ return (n != strValue); });
			list_subj_taken.val(arr.join(", "));
			$('#hidden_subj_id'+strID).val(0);
			$('#but_subj_id'+strID).attr('src','./application/images/icon/checkbox_uncheck.png');
		}
		
	}
</script>
</body>
</html>
